package com.jml.juc.lock;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 可重入锁
 */
class PhonePlus {

    Lock lock = new ReentrantLock();
    public void method01(){
        lock.lock();
        try {
            System.out.println(Thread.currentThread().getName()+"=====method01.....");
            method02();
        } finally {
            lock.unlock();
        }

    }

    public void method02(){
        lock.lock();
        try {
            System.out.println(Thread.currentThread().getName()+"=====method02.....");
        } finally {
            lock.unlock();
        }

    }
}

public class ReentrantLockDemo {
    public static void main(String[] args) {
        PhonePlus phonePlus = new PhonePlus();

        new Thread(()->{
            phonePlus.method01();
        }, "A").start();

        new Thread(()->{
            phonePlus.method01();
        }, "B").start();
    }

}
